#include "structs/Iterable.h"

#include <Listener.h>
#include <base/buffer.h>
#include <base/match.hpp>
#include <base/time_utils.hpp>
#include <iostream>
#include <math/math.h>
#include <structs/Arrays.hpp>
#include <structs/LinkList/LinkList.hpp>
#include <base/optional.hpp>
#include <thread>
using namespace std;
#include <base/ThreadPool.h>
#include <base/log.hpp>
#include <atomic>
using namespace tbs::structs::link_list;
using namespace tbs::math;
using namespace tbs;
#undef INUSE_LOGGERS

#undef LOG_LEVEL

#define LOG_LEVEL L_ERROR

#include <base/loggers/BuiltInLogger.h>

BuiltInLoggers::ConsoleLogger mainLogger("main-logger");

#define INUSE_LOGGERS &mainLogger

void simpleTest() {
  Decimal d{"0001123456676342798787123984781237486757.8220231232314234"};
  Decimal d2{"1123456676342798787123984781237486757.89202"};
//  auto c = d + d2;//31
//  d += d2;//28
//  d -= d2;//54
//  auto c = d - d2;//55
  auto c = d * d2;//203
//  auto c = d > d2;//14
}

int main(int argc, char const *argv[]) {
  useThreadPool({ThreadPoolConfig("main"), ThreadPoolConfig("sec"), ThreadPoolConfig("third")});
  time_utils::timeUnit c = 0;
  for (int k = 0; k < 5; k++) {
	time_utils::timeUnit a = time_utils::utils_now();
	atomic_int cnt = 0;
	for (int i = 0; i < 5; i++) {
	  submitTask(createTask([&cnt](void *data, unsigned long size, const char *threadName, unsigned long long taskId) {
		DEBUG_LOG("threadName: {}, taskId: {}", threadName, taskId);
		for (int j = 0; j < 20000; j++) {
		  simpleTest();
		}
		cnt++;
	  }));
	}
	while (cnt < 4) {
	  this_thread::yield();
	}
	time_utils::timeUnit b = time_utils::utils_now();
	c += b - a;
	cout << c << endl;
  }
  cout << c / 5 << endl;

  return 0;
}